package com.threeonemeeting.activity.ext;

import java.util.ArrayList;
import java.util.Map;

import android.graphics.Color;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;

import com.threeonemeeting.R;
import com.threeonemeeting.activity.CallBackActivity;
import com.threeonemeeting.listview.DragRefreshListView;

/**
 * @desc 如果页面的主要内容是列表，并且需要支持分页，并且支持下拉刷新， 那么可以从 PageListActivity继承
 * @author Administrator
 * 
 */
public class PageListActivity extends CallBackActivity implements
		OnItemClickListener {

	protected LinearLayout noRecordLayout = null;
	protected LinearLayout loadingLayout = null;
	protected LinearLayout listLayout = null;
	protected LinearLayout loadingMoreLayout = null;
	protected DragRefreshListView meetingListView = null;

	// 当前的所有页面是否需要刷新
	protected boolean bRefresh = false;

	// 强制刷新的时候各个页面是否已经刷新过
	protected ArrayList<Boolean> listRefresh = new ArrayList<Boolean>();

	public void setContentView(int layoutResId, String strTitle) {
		setContentView(layoutResId);

		init(strTitle);

		noRecordLayout = (LinearLayout) findViewById(R.id.norecord_layout);
		loadingLayout = (LinearLayout) findViewById(R.id.loading_layout);
		listLayout = (LinearLayout) findViewById(R.id.list_layout);
		loadingMoreLayout = (LinearLayout) findViewById(R.id.layout_loading_more);

		meetingListView = (DragRefreshListView) findViewById(R.id.lv_meeting_list);
		meetingListView.setCacheColorHint(Color.TRANSPARENT);
		meetingListView.setOnItemClickListener(this);

		showLoadingLayout();
	}

	public DragRefreshListView getListView() {
		return meetingListView;
	}

	/**
	 * @desc 显示加载提示窗口
	 * @param bShow
	 */
	protected void showLoadingLayout() {
		loadingLayout.setVisibility(View.VISIBLE);
		listLayout.setVisibility(View.GONE);
		noRecordLayout.setVisibility(View.GONE);
		loadingMoreLayout.setVisibility(View.GONE);
	}

	/**
	 * @desc 显示列表窗口，如果列表为0，则显示没有记录
	 * @param bShow
	 */
	protected void showListLayout(int nListItemCount) {

		loadingLayout.setVisibility(View.GONE);
		if (nListItemCount == 0) {
			listLayout.setVisibility(View.GONE);
			noRecordLayout.setVisibility(View.VISIBLE);
		} else {
			listLayout.setVisibility(View.VISIBLE);
			noRecordLayout.setVisibility(View.GONE);
		}
	}

	/**
	 * @desc 显示加载更多的状态窗口
	 * @param bShow
	 */
	protected void showLoadingMoreLayout(boolean bShow) {

		if (bShow == true) {
			loadingMoreLayout.setVisibility(View.VISIBLE);

		} else {
			loadingMoreLayout.setVisibility(View.GONE);
		}
	}

	public void onFailedCallBack(Map<String, Object> mapData) {

	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int position,
			long id) {
	}
}
